# coding=utf-8
# @time     :2021/12/16
# @Author   :Simple
# @FileName :tst
# @Project  :learn_pytest
import json

import pytest
from filelock import FileLock


@pytest.fixture(scope="session")
def session_data(tmp_path_factory, worker_id):
    if worker_id == "master":
        return produce_expensive_data()

    root_tmp_dir = tmp_path_factory.getbasetemp().parent

    fn = root_tmp_dir / 'user.json'
    with FileLock(str(fn) + ".lock"):
        if fn.is_file():
            data = json.loads(fn.read_text())
        else:
            data = produce_expensive_data()
            fn.write_text(json.dumps(data))
    return data


def produce_expensive_data():
    return ""
